home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / manual / examples / add.c next >
C/C++ Source or Header  |  1994-02-16  |  520b  |  31 lines

  1. #include <stdarg.h>
  2. #include <stdio.h>
  3.  
  4. int
  5. add_em_up (int count,...)
  6. {
  7.   va_list ap;
  8.   int i, sum;
  9.  
  10.   va_start (ap, count);        /* Initialize the argument list. */
  11.  
  12.   sum = 0;
  13.   for (i = 0; i < count; i++)
  14.     sum += va_arg (ap, int);    /* Get the next argument value. */
  15.  
  16.   va_end (ap);            /* Clean up. */
  17.   return sum;
  18. }
  19.  
  20. int
  21. main (void)
  22. {
  23.   /* This call prints 16. */
  24.   printf ("%d\n", add_em_up (3, 5, 5, 6));
  25.  
  26.   /* This call prints 55. */
  27.   printf ("%d\n", add_em_up (10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
  28.  
  29.   return 0;
  30. }
  31.